<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/23
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>鸿蒙-神舟后台管理</title>
    <%@include file="/common/head.jsp" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <style>
        .form-horizontal .form-group {
            margin-right: 0px;
            margin-left: 0px;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <%@include file="/common/navi.jsp" %>


    <%--    <这里是中间主体>--%>
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <%@include file="/common/row_head.jsp" %>


        <%--        <可更改地区>--%>
        <%--            <上面的分块 建议不要改div class中的东西>--%>
        <div class="row  border-bottom white-bg dashboard-header">
            <div class="col-sm-3">
                <h1>图书管理</h1>
            </div>
            <div class="col-sm-6">

                <div class="flot-chart dashboard-chart">
                    <div class="flot-chart-content" id="flot-dashboard-chart"></div>
                </div>
                <div class="row text-left">
                    <div class="col-xs-4">
                        <div class=" m-l-md">
                            <span class="h4 font-bold m-t block">$ 406,100</span>
                            <small class="text-muted m-b block">Sales marketing report</small>
                        </div>
                    </div>
                    <div class="col-xs-4">
                        <span class="h4 font-bold m-t block">$ 150,401</span>
                        <small class="text-muted m-b block">Annual sales revenue</small>
                    </div>
                    <div class="col-xs-4">
                        <span class="h4 font-bold m-t block">$ 16,822</span>
                        <small class="text-muted m-b block">Half-year revenue margin</small>
                    </div>

                </div>
            </div>
            <div class="col-sm-3">
                <div class="statistic-box">
                    <h4>
                        Project Beta progress
                    </h4>
                    <p>
                        You have two project with not compleated task.
                    </p>
                    <div class="row text-center">
                        <div class="col-lg-6">
                            <canvas id="polarChart" width="80" height="80"></canvas>
                            <h5>Kolter</h5>
                        </div>
                        <div class="col-lg-6">
                            <canvas id="doughnutChart" width="78" height="78"></canvas>
                            <h5>Maxtor</h5>
                        </div>
                    </div>
                    <div class="m-t">
                        <small>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</small>
                    </div>

                </div>
            </div>

        </div>


        <%--                <下面的分块 建议不要改div class中的东西>--%>
        <div class="row">
            <div class="col-lg-12">
                <div class="wrapper wrapper-content">
                            <div class="ibox float-e-margins">
                                <div class="ibox-title">
                                    <h5>CYBERTHREAT REAL-TIME MAP</h5>
                                    <div class="ibox-tools">
                                        <a class="collapse-link">
                                            <i class="fa fa-chevron-up"></i>
                                        </a>
                                        <a class="dropdown-toggle" data-toggle="dropdown" href="index.html#">
                                            <i class="fa fa-wrench"></i>
                                        </a>
                                        <ul class="dropdown-menu dropdown-user">
                                            <li><a href="index.html#">Config option 1</a>
                                            </li>
                                            <li><a href="index.html#">Config option 2</a>
                                            </li>
                                        </ul>
                                        <a class="close-link">
                                            <i class="fa fa-times"></i>
                                        </a>

                                        <span class="label label-warning-light pull-right">10 Messages</span>

                                    </div>
                                </div>
                                <div class="ibox-content">
                    <form role="form" id="_infoForm">
                        <div class="form-group">
                            <input class="col-md-1" id="_queryBookById" type="text" placeholder="书籍Id"/>
                        </div>
                        <div class="form-group">
                            <input class="col-md-2" id="_queryBookByName" type="text" placeholder="书籍名称"/>
                        </div>
                        <div class="form-group">
                            <select class="col-md-2 " id="_queryBookByType" onclick="querySecondType()" >
                                <option value="0">一级分类</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <select class="col-md-2" id="_queryBookBySecondType">
                                <option value="">二级分类</option>
                            </select>
                        </div>
                    </form>
                    <input type="button" class="btn btn-success" value="查询" onclick="queryBookByInfo()"></input>
                </div>
                <div class="wrapper wrapper-content">
                    <input class="btn btn-default" type="button" value="添加" onclick="addBook()">
                    <div>
                        <div class="modal fade" tabindex="-1" role="dialog">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span></button>
                                        <h4 class="modal-title">Modal title</h4>
                                    </div>
                                    <div class="modal-body">
                                        <p>One fine body&hellip;</p>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close
                                        </button>
                                        <button type="button" class="btn btn-primary">Save changes</button>
                                    </div>
                                </div><!-- /.modal-content -->
                            </div><!-- /.modal-dialog -->
                        </div><!-- /.modal --></div>
                    <div class="modal fade" id="_addBoook" tabindex="-1"
                         aria-labelledby="add_book_label" aria-hidden="true">
                        <div class="modal-dialog modal-lg">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                    <h4 class="modal-title" id="_exampleModalLabel">添加小说</h4>
                                </div>
                                <div class="modal-body">
                                    <form method="post" class="form-horizontal" id="_addBookForm">
                                        <!--表单项-->
                                        <div class="form-group">
                                            <label for="addBookId" class="control-label">小说Id</label>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="addBookId" id="addBookId">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="addBookName" class="control-label">小说名称</label>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="addBookName"
                                                       id="addBookName">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="addBookAuthor" class="control-label">小说作者</label>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="addBookAuthor"
                                                       id="addBookAuthor">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="addFtypeId" class="control-label ">一级分类</label>
                                            <div class="form-group">
                                                <select name="addFtypeId" id="addFtypeId" class="form-control"
                                                        onchange="addQueryCategory(this)">
                                                    <option value="">---请选择---</option>
                                                </select>
                                            </div>
                                            <label for="addStype" class="control-label  ">二级分类</label>
                                            <div class="form-group">
                                                <select name="addStype" id="addStype" class="form-control">
                                                    <option value="">---请选择---</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="addWordCount" class="control-label">字数统计</label>
                                            <div class="form-group">
                                                <div class="input-group">
                                                    <input type="text" class="form-control" name="addWordCount"
                                                           id="addWordCount">
                                                    <div class="input-group-addon">万字</div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="addStatus" class=" control-label">更新状态</label>
                                            <div class="form-group">
                                                <select name="addStatus" id="addStatus" class="form-control">
                                                    <option value="0">连载</option>
                                                    <option value="1">完结</option>
                                                </select>
                                            </div>
                                            <label for="addIsVip" class=" control-label">是否收费</label>
                                            <div class="form-group">
                                                <select name=addIsVip id="addIsVip" class="form-control">
                                                    <option value="0">免费</option>
                                                    <option value="1">收费</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="addStatusUp" class=" control-label">状态设置</label>
                                            <p class="help-block">(上架状态)</p>
                                            <div class="form-group">
                                                <select name="addStatusUp" id="addStatusUp" class="form-control">
                                                    <option value="1">可用</option>
                                                    <option value="1">下架</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="addImgUrl" class=" control-label">小说封面</label>
                                            <div class="form-group">
                                                <input type="text" name="addImgUrl" id="addImgUrl">
                                                <span>请输入URL地址</span>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label for="addDescription" class=" control-label">小说描述</label>
                                            <div class="form-group">
                                                    <textarea class="form-control" name="addDescription"
                                                              id="addDescription"
                                                              rows="5"></textarea>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="addSubmit" onclick="addSubmit()">
                                        保存
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table class="table">
                        <thead>
                        <tr>
                            <th>
                                书籍ID
                            </th>
                            <th>
                                书籍名称
                            </th>
                            <th>
                                作者
                            </th>
                            <th>
                                一级分类id
                            </th>
                            <th>
                                一级分类名称
                            </th>
                            <th>
                                二级分类id
                            </th>
                            <th>
                                二级分类名称
                            </th>
                            <th>
                                更新状态
                            </th>
                            <th>
                                操作
                            </th>
                        </tr>
                        </thead>
                        <tbody id="book_table_data">
                        <div class="modal fade" id="novel_form_edit" tabindex="-1"
                             aria-labelledby="novel_form_edit_label" aria-hidden="true">
                            <div class="modal-dialog modal-lg">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                        <h4 class="modal-title" id="exampleModalLabel">修改小说</h4>
                                    </div>
                                    <div class="modal-body">
                                        <form method="post" class="form-horizontal" id="novel_edit_form">
                                            <!--Identifier-->
                                            <input type="hidden" id="bookId" name="bookId" value="">
                                            <!--表单项-->
                                            <div class="form-group">
                                                <label for="bookName" class="control-label">小说名称</label>
                                                <div class="form-group">
                                                    <input type="text" class="form-control" name="bookName"
                                                           id="bookName">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="bookAuthor" class="control-label">小说作者</label>
                                                <div class="form-group">
                                                    <input type="text" class="form-control" name="bookAuthor"
                                                           id="bookAuthor">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="ftypeId" class="control-label ">一级分类</label>
                                                <div class="form-group">
                                                    <select name="ftypeId" id="ftypeId" class="form-control"
                                                            onchange="queryCategory(this)">
                                                        <option value="">---请选择---</option>
                                                    </select>
                                                </div>
                                                <label for="stype" class="control-label  ">二级分类</label>
                                                <div class="form-group">
                                                    <select name="stype" id="stype" class="form-control">
                                                        <option value="">---请选择---</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="wordCount" class="control-label">字数统计</label>
                                                <div class="form-group">
                                                    <div class="input-group">
                                                        <input type="text" class="form-control" name="wordCount"
                                                               id="wordCount">
                                                        <div class="input-group-addon">万字</div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="status" class=" control-label">更新状态</label>
                                                <div class="form-group">
                                                    <select name="status" id="status" class="form-control">
                                                        <option value="0">连载</option>
                                                        <option value="1">完结</option>
                                                    </select>
                                                </div>
                                                <label for="isVip" class=" control-label">是否收费</label>
                                                <div class="form-group">
                                                    <select name=isVip id="isVip" class="form-control">
                                                        <option value="0">免费</option>
                                                        <option value="1">收费</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="statusUp" class=" control-label">状态设置</label>
                                                <p class="help-block">(上架状态)</p>
                                                <div class="form-group">
                                                    <select name="statusUp" id="statusUp" class="form-control">
                                                        <option value="1">可用</option>
                                                        <option value="1">下架</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="imgUrl" class=" control-label">小说封面</label>
                                                <div class="form-group">
                                                    <input type="text" name="imgUrl" id="imgUrl">
                                                    <span>请输入URL地址</span>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label for="description" class=" control-label">小说描述</label>
                                                <div class="form-group">
                                                    <textarea class="form-control" name="description" id="description"
                                                              rows="5"></textarea>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                                        <button type="button" class="btn btn-primary" id="btn_edit_submit">保存</button>
                                    </div>
                                </div>
                                <%@include file="../../common/foot.jsp" %>

                            </div></div>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>


    </div>
        <%@include file="../../common/page_ajax.jsp" %>
        <%@include file="/common/foot.jsp" %>
    </div></div>
    <script>
        $(document).ready(function () {
            setTimeout(function () {
                toastr.options = {
                    closeButton: true,
                    progressBar: true,
                    showMethod: 'slideDown',
                    timeOut: 4000
                };
                toastr.success('欢迎来到图书管理', '欢迎来到神舟-鸿蒙后台系统');

            }, 1300);


            var data1 = [
                [0, 4], [1, 8], [2, 5], [3, 10], [4, 4], [5, 16], [6, 5], [7, 11], [8, 6], [9, 11], [10, 30], [11, 10], [12, 13], [13, 4], [14, 3], [15, 3], [16, 6]
            ];
            var data2 = [
                [0, 1], [1, 0], [2, 2], [3, 0], [4, 1], [5, 3], [6, 1], [7, 5], [8, 2], [9, 3], [10, 2], [11, 1], [12, 0], [13, 2], [14, 8], [15, 0], [16, 0]
            ];
            $("#flot-dashboard-chart").length && $.plot($("#flot-dashboard-chart"), [
                    data1, data2
                ],
                {
                    series: {
                        lines: {
                            show: false,
                            fill: true
                        },
                        splines: {
                            show: true,
                            tension: 0.4,
                            lineWidth: 1,
                            fill: 0.4
                        },
                        points: {
                            radius: 0,
                            show: true
                        },
                        shadowSize: 2
                    },
                    grid: {
                        hoverable: true,
                        clickable: true,
                        tickColor: "#d5d5d5",
                        borderWidth: 1,
                        color: '#d5d5d5'
                    },
                    colors: ["#1ab394", "#1C84C6"],
                    xaxis: {},
                    yaxis: {
                        ticks: 4
                    },
                    tooltip: false
                }
            );

            var doughnutData = [
                {
                    value: 300,
                    color: "#a3e1d4",
                    highlight: "#1ab394",
                    label: "App"
                },
                {
                    value: 50,
                    color: "#dedede",
                    highlight: "#1ab394",
                    label: "Software"
                },
                {
                    value: 100,
                    color: "#A4CEE8",
                    highlight: "#1ab394",
                    label: "Laptop"
                }
            ];

            var doughnutOptions = {
                segmentShowStroke: true,
                segmentStrokeColor: "#fff",
                segmentStrokeWidth: 2,
                percentageInnerCutout: 45, // This is 0 for Pie charts
                animationSteps: 100,
                animationEasing: "easeOutBounce",
                animateRotate: true,
                animateScale: false
            };

            var ctx = document.getElementById("doughnutChart").getContext("2d");
            var DoughnutChart = new Chart(ctx).Doughnut(doughnutData, doughnutOptions);

            var polarData = [
                {
                    value: 300,
                    color: "#a3e1d4",
                    highlight: "#1ab394",
                    label: "App"
                },
                {
                    value: 140,
                    color: "#dedede",
                    highlight: "#1ab394",
                    label: "Software"
                },
                {
                    value: 200,
                    color: "#A4CEE8",
                    highlight: "#1ab394",
                    label: "Laptop"
                }
            ];

            var polarOptions = {
                scaleShowLabelBackdrop: true,
                scaleBackdropColor: "rgba(255,255,255,0.75)",
                scaleBeginAtZero: true,
                scaleBackdropPaddingY: 1,
                scaleBackdropPaddingX: 1,
                scaleShowLine: true,
                segmentShowStroke: true,
                segmentStrokeColor: "#fff",
                segmentStrokeWidth: 2,
                animationSteps: 100,
                animationEasing: "easeOutBounce",
                animateRotate: true,
                animateScale: false
            };
            var ctx = document.getElementById("polarChart").getContext("2d");
            var Polarchart = new Chart(ctx).PolarArea(polarData, polarOptions);

        });
    </script>
    <script>
        (function (i, s, o, g, r, a, m) {
            i['GoogleAnalyticsObject'] = r;
            i[r] = i[r] || function () {
                (i[r].q = i[r].q || []).push(arguments)
            }, i[r].l = 1 * new Date();
            a = s.createElement(o),
                m = s.getElementsByTagName(o)[0];
            a.async = 1;
            a.src = g;
            m.parentNode.insertBefore(a, m)
        })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

        ga('create', 'UA-4625583-2', 'webapplayers.com');
        ga('send', 'pageview');

    </script>
    <script>
        $(function () {
            query()
            queryFillType();
            bindSubmit()
        })

        function queryBookByInfo() {
            var url = 'book/queryBookByInfo';
            var param = {
                'bookId': $("#_queryBookById").val(),
                'bookName': $("#_queryBookByName").val(),
                'typeId': $("#_queryBookByType").val(),
                'secondTypeId': $("#_queryBookBySecondType").val()
            }
            $.getJSON(url, param, function (pageInfo) {
                if (pageInfo != 0) {
                    if(pageInfo.list==null){
                        $("#book_table_data").empty();
                            var isUpdating = pageInfo.status == 1 ? "连载中" : "完结"
                            var html = '<tr>';
                            html += '<td>' + pageInfo.bookId + '</td>';
                            html += '<td>' + pageInfo.bookName + '</td>';
                            html += '<td>' + pageInfo.authorName + '</td>';
                            html += '<td>' + pageInfo.ftypeId + '</td>';
                            html += '<td>' + pageInfo.typeName + '</td>';
                            html += '<td>' + pageInfo.stypeId + '</td>';
                            html += '<td>' + pageInfo.secondTypeName + '</td>';
                            html += '<td>' + isUpdating + '</td>';
                            html += '<td><input type="button" value="修改" class="btn btn-primary" onclick="queryBookInfo(' + pageInfo.bookId + ')"></td>';
                            html += '</tr>';
                            $("#book_table_data").append(html);
                    }else {
                        $("#book_table_data").empty();
                        $.each(pageInfo.list, function (index, item) {
                            var isUpdating = item.status == 1 ? "连载中" : "完结"
                            var html = '<tr>';
                            html += '<td>' + item.bookId + '</td>';
                            html += '<td>' + item.bookName + '</td>';
                            html += '<td>' + item.authorName + '</td>';
                            html += '<td>' + item.ftypeId + '</td>';
                            html += '<td>' + item.typeName + '</td>';
                            html += '<td>' + item.stypeId + '</td>';
                            html += '<td>' + item.secondTypeName + '</td>';
                            html += '<td>' + isUpdating + '</td>';
                            html += '<td><input type="button" value="修改" class="btn btn-primary" onclick="queryBookInfo(' + item.bookId + ')"></td>';
                            html += '</tr>';
                            $("#book_table_data").append(html);
                        })
                     }
                } else {
                    alert("未查询到,显示全部")
                    $("#book_table_data").empty();
                    query()
            }
        })
        }

        function addBook() {
            $(":input text").val(" ");
            $("#_addBoook").modal({
                keyboard: false,
                backdrop: 'static'
            });
            addfillType()
        }

        function addSubmit() {
            $.ajax({
                url: 'book/addBook',
                type: 'post',
                data: {
                    "bookId": $("#addBookId").val(),
                    "bookName": $("#addBookName").val(),
                    "bookAuthor": $("#addBookAuthor").val(),
                    "wordCount": $("#addWordCount").val(),
                    "status": $("#addStatus").val(),
                    "isVip": $("#addIsVip").val(),
                    "statusUp": $("#addStatusUp").val(),
                    "ftypeId": $("#addFtypeId").val(),
                    "stypeId": $("#addStype").val(),
                    "description": $("#addDescription").val(),
                    "cover_url": $("#addImgUrl").val()
                },
                success: function (data) {

                    if (data > 0) {
                        alert("添加成功")
                        $("#novel_form_edit").modal('hide')
                    } else {
                        alert("添加失败，有空字段")
                    }
                }
            })
        }

        function addQueryCategory(obj) {
            addFillSecondType(obj.value)
        }

        function addFillSecondType(ftypeId) {
            console.log(ftypeId)
            $("#addStype").empty();
            var secondTypeUrl = "book/secondType"
            var typeId = {
                "ftypeId": ftypeId
            }
            var addcount = 0
            $.getJSON(secondTypeUrl, typeId, function (data) {
                console.log(data)
                $.each(data, function (index, item) {
                    addcount++;
                    var html = "<option value='" + item.typeId + "'>" + item.secondTypeName + "</option>"
                    $("#addStype").append(html)
                    // if (count >= $(data).length && secondTypeId != null && secondTypeId >= 0) {
                    //     $("#addStype").val(secondTypeId)
                    // }
                })
            })
        }

        function addfillType() {
            /*回填一级分类*/
            var cUrl = 'book/type';
            $.getJSON(cUrl, function (data) {
                $("#addFtypeId").empty();
                $("#addFtypeId").append( '<option value="' + item.typeId + '">全部</option>')
                $.each(data, function (index, item) {
                    var html = '<option value="' + item.typeId + '">' + item.typeName + '</option>';
                    $("#addFtypeId").append(html)
                })
            });
        }

        function query() {
            var url = 'book/queryBook';
            var param = {
                "pageNum": $("#pageNum").text(),
                "pageSize": $("#pageSize").val()
            };
            $.getJSON(url, param, function (pageInfo) {
                $("#book_table_data").empty();
                $.each(pageInfo.list, function (index, item) {
                    var isUpdating = item.status == 1 ? "连载中" : "完结"
                    var html = '<tr>';
                    html += '<td>' + item.bookId + '</td>';
                    html += '<td>' + item.bookName + '</td>';
                    html += '<td>' + item.authorName + '</td>';
                    html += '<td>' + item.ftypeId + '</td>';
                    html += '<td>' + item.typeName + '</td>';
                    html += '<td>' + item.stypeId + '</td>';
                    html += '<td>' + item.secondTypeName + '</td>';
                    html += '<td>' + isUpdating + '</td>';
                    html += '<td><input type="button" value="修改" class="btn btn-primary" onclick="queryBookInfo(' + item.bookId + ')"></td>';
                    html += '</tr>';
                    $("#book_table_data").append(html);
                })
                pageData(pageInfo);
            })
        }

        function queryBookInfo(bookId) {
            $(":input text").val("");
            fillModalDate(bookId);
            /*打开模块框*/
            $("#novel_form_edit").modal({
                keyboard: false,
                backdrop: 'static'
            });
        }

        function fillModalDate(bookId) {
            /*回填数据*/
            var url = 'book/queryBookById';
            var param = {
                'bookId': bookId
            }
            $.getJSON(url, param, function (data) {
                $("#bookId").val(data.bookId);
                $("#bookName").val(data.bookName);
                $("#bookAuthor").val(data.authorName);
                $("#wordCount").val(data.wordCount);
                $("#status").val(data.status);
                $("#isVip").val(data.isVip);
                $("#statusUp").val(data.statusUp);
                $("#ftypeId").val(data.ftypeId);
                $("#imgUrl").val(data.coverUrl)
                $("#description").val(data.description);
                //回填一级分类
                fillType();
                //回填二级分类
                fillSecondType(data.ftypeId, data.stypeId)
            })
        }

        function bindSubmit() {
            //    表单校验

            //提交
            $("#btn_edit_submit").click(function () {

                $.ajax({
                    url: 'book/updateBook',
                    type: 'post',
                    data: {
                        "bookId": $("#bookId").val(),
                        "bookName": $("#bookName").val(),
                        "bookAuthor": $("#bookAuthor").val(),
                        "wordCount": $("#wordCount").val(),
                        "status": $("#status").val(),
                        "isVip": $("#isVip").val(),
                        "statusUp": $("#statusUp").val(),
                        "ftypeId": $("#ftypeId").val(),
                        "stypeId": $("#stype").val(),
                        "description": $("#description").val(),
                        "cover_url": $("#imgUrl").val()
                    },
                    success: function (data) {
                        if (data == 1) {
                            alert("修改成功")
                            $("#novel_form_edit").modal('hide')
                        } else {
                            alert("有空值，请检查")
                        }
                    }
                })
            })
        }

        function fillType() {
            /*回填一级分类*/
            var cUrl = 'book/type';
            $.getJSON(cUrl, function (data) {
                $("#ftypeId").empty();
                $.each(data, function (index, item) {
                    var html = '<option value="' + item.typeId + '">' + item.typeName + '</option>';
                    $("#ftypeId").append(html)
                })
            });
        }

        function queryFillType() {
            /*回填一级分类*/

            var cUrl = 'book/type';
            $.getJSON(cUrl, function (data) {
                $("#_queryBookByType").empty();
                // $("#_queryBookByType").append('<option></option>')
                $.each(data, function (index, item) {
                    var html = '<option value="' + item.typeId + '">' + item.typeName + '</option>';
                    $("#_queryBookByType").append(html)
                })
            });
        }

        function querySecondType() {
            var queryFtype = $("#_queryBookBySecondType").parent().prev().children();

            $("#_queryBookBySecondType").empty();
            var secondTypeUrl = "book/secondType"
            var typeId = {
                "ftypeId": queryFtype.val()
            }
            $.getJSON(secondTypeUrl, typeId, function (data) {
                $.each(data, function (index, item) {
                    var html = "<option value='" + item.typeId + "'>" + item.secondTypeName + "</option>"
                    $("#_queryBookBySecondType").append(html)
                })
            })
        }

        function fillSecondType(ftypeId, secondTypeId) {
            $("#stype").empty();
            var secondTypeUrl = "book/secondType"
            var typeId = {
                "ftypeId": ftypeId
            }
            var count = 0
            $.getJSON(secondTypeUrl, typeId, function (data) {
                $.each(data, function (index, item) {
                    count++;
                    var html = "<option value='" + item.typeId + "'>" + item.secondTypeName + "</option>"
                    $("#stype").append(html)
                    if (count >= $(data).length && secondTypeId != null && secondTypeId >= 0) {
                        $("#stype").val(secondTypeId)
                    }
                })
            })
        }

        function queryCategory(obj) {
            fillSecondType(obj.value)
        }
    </script>
</body>
</html>
